package com.csx.base.utils;

import com.yh.csx.bsf.core.base.Callable;
import com.yh.csx.bsf.core.util.ThreadUtils;

import java.util.ArrayList;
import java.util.Collection;

public class ThreadUtil {
    public static void sleep(int mSecond){
        try{Thread.sleep(mSecond);}catch (Exception e){}
    }
    public static <T> void parallelFor(String taskName, int parallelCount, Collection<T> taskList, Callable.Action1<T> action) {
        if(parallelCount == 1)
        {
            taskList.forEach(task->{
                try {
                    action.invoke(task);
                } catch (Exception e) {
                    throw e;
                }
            });
        }
        else {
            ThreadUtils.parallelFor(taskName, parallelCount, new ArrayList<>(taskList), action);
        }
    }
}
